/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package deatax.display.particle;

/**
 *
 * @author nrechten
 */
public class VectorRule extends ParticleRule {

    float[] inital = new float[]{0,0,0};
    float[] vector = new float[]{0,0,0};

    public VectorRule(float[] inital, float[] vector, float derivative, float min, float max) {
        this.inital = inital;
        this.vector = vector;
        this.derivative = derivative;
        this.max = max;
        this.min = min;
    }

    @Override
    public void init(float[] f, int index) {
//        System.out.println("init" + f[index]);
        f[index] = derivative>0?min:max;
//        System.out.println("init:" + f[index]);
    }

    @Override
    public void apply(float[] f, int index, int index_r, float scale, float[] p, float age) {
        f[index_r] = Math.min(Math.max(min, f[index_r]+derivative*scale), max);
        
        f[index+1] += (vector[0]*f[index_r]+inital[0])*scale;
        f[index+2] += (vector[1]*f[index_r]+inital[1])*scale;
        f[index+3] += (vector[2]*f[index_r]+inital[2])*scale;
    }

}
